package com.CMS.server.dao;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import com.CMS.server.domain.Galery;
import com.CMS.server.domain.PageVersion;
import com.CMS.server.domain.User;


public class GaleryDao extends BaseDao<Galery>{
	
	public GaleryDao()
	{
		super();
	}
	
	public boolean isExistName(String name)
	{
		Galery g = null;
		EntityManager em = entityManager();
		try{
			Query q = em.createQuery("select g from Galery g where g.name = '"+ name +"'");
			try{
				g = (Galery) q.getSingleResult();
			}
			catch(Exception e){
				q = null;
			}
			
			if(q != null)
			   return true;
			else
		       return false;
		}
		finally{
			em.close();
		}
	}
	
	public boolean asociatedPageGallery(long idPage)
	{
		Galery g = null;
		EntityManager em = entityManager();
		try{
			Query q = em.createQuery("select g from Galery g where g.page = '"+ idPage +"'");
			try{
				g = (Galery) q.getSingleResult();
			}
			catch(Exception e){
				q = null;
			}
			
			if(q != null)
			   return true;
			else
		       return false;
		}
		finally{
			em.close();
		}
	}

}
